package com.wnxy.eleba.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wnxy.eleba.entity.Dishes;
import com.wnxy.eleba.mapper.DishesMapper;
import com.wnxy.eleba.service.DishesService_zhuying;
import com.wnxy.eleba.vo.DishesQueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class DishesServiceImpl_zhuying implements DishesService_zhuying {
    private DishesMapper dishesMapper;

    @Autowired
    public void setDishesMapper(DishesMapper dishesMapper) {
        this.dishesMapper = dishesMapper;
    }

    @Override
    public Dishes findDishesById(Integer DishesId) {
        return dishesMapper.selectByPrimaryKey(DishesId);
    }

    @Override
    public List<Dishes> findAll() {
        List<Dishes> DishesList = dishesMapper.showAll();

        return DishesList;
    }

    @Override
    public PageInfo<Dishes> listDishesPageByCondition(DishesQueryParam DishesQueryParam) {
        PageHelper.startPage(DishesQueryParam.getCurrentPage(),DishesQueryParam.getPageSize());
        List<Dishes> DishesList = dishesMapper.selectDishesByCondition(DishesQueryParam);
        PageInfo<Dishes> pageInfo = new PageInfo<>(DishesList);
        return pageInfo;
    }

    @Override
    public boolean saveDishes(Dishes Dishes) {
        return dishesMapper.insert(Dishes)!=0;
    }

    @Override
    public boolean updateDishes(Dishes Dishes) {
        return dishesMapper.updateByPrimaryKey(Dishes)!=0;
    }

    @Override
    public boolean deleteDishes(Integer[] ids) {
        return dishesMapper.del(Arrays.asList(ids))!=0;
    }

    @Override
    public boolean delDishes(Integer id) {
        return dishesMapper.deleteByPrimaryKey(id)!=0;
    }

    @Override
    public List<String> listDishesType() {
        return dishesMapper.listAllDishesType();
    }
}
